package com.iweb.newa202104.service.impl;

import com.iweb.newa202104.Mapper.ResourceMapper;
import com.iweb.newa202104.dto.QuestionOutputDTO;
import com.iweb.newa202104.dto.ResourceInputDTO;
import com.iweb.newa202104.dto.ResourceOutputDTO;
import com.iweb.newa202104.entity.QuestionEntity;
import com.iweb.newa202104.entity.ResourceEntity;
import com.iweb.newa202104.enums.Err;
import com.iweb.newa202104.exception.CommonException;
import com.iweb.newa202104.service.ResourceService;
import com.iweb.newa202104.util.CommonUtil;
import com.iweb.newa202104.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.TransientDataAccessResourceException;
import org.springframework.stereotype.Service;

/**
 * description:  <br>
 * date: 2021/5/12 20:17 <br>
 * author: ztz <br>
 * version: 1.0 <br>
 */
@Service
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    ResourceMapper resourceMapper;

    @Override
    public ResultVO getResourceByCategory(int categoryId) {
        try {
            ResourceEntity resourceEntity = new ResourceEntity();
            resourceEntity.setCategoryId(categoryId);
            ResourceOutputDTO[] resourceOutputDTO = resourceMapper.getResourceByCategory(resourceEntity);
            return CommonUtil.ajaxReturn(resourceOutputDTO);
        } catch (TransientDataAccessResourceException e) {
            throw new CommonException(Err.PRAM_ERR);
        }
    }
}
